package za.org.jcicada.genss.lifecycle.impl;

/**
 * LifeCycleAcceptListener.java
 *
 * @author Simon Cross
 *
 * Created on February 9, 2009, 16:11
 */

import za.org.jcicada.comms.IConnection;
import za.org.jcicada.comms.IKatcpSerializerStrategy;
import za.org.jcicada.comms.IMessageListener;
import za.org.jcicada.comms.impl.AcceptListenerBase;
import za.org.jcicada.genss.lifecycle.ILifeCycleServer;
import za.org.jcicada.genss.lifecycle.katcp.LifecycleKatcpSerializer;

/**
 * Katcomms accept listener that accepts connections and ties them to
 * a given ILifeCycleServer.
 */
public class LifeCycleAcceptListener extends AcceptListenerBase {

    /**
     * ILifeCycleServer implementation to delegate requests to.
     */
    protected ILifeCycleServer lifeCycleServer;

    /**
     * Create an accept listener that accept clients and passes
     * messages through to the given ILifeCycleServer implementation.
     */
    public LifeCycleAcceptListener(ILifeCycleServer lifeCycleServer) {
        this.lifeCycleServer = lifeCycleServer;

    }

    /**
     * Create message listeners for new connections.
     * Implements abstract method from AcceptListenerBase.
     *
     * @param connection  New connection from client.
     */
    public IMessageListener createListener(IConnection connection) {
        return new LifeCycleMessaging(connection, lifeCycleServer);
    }

	@Override
	public IKatcpSerializerStrategy getKatcpSerializerStrategy() {
		return new LifecycleKatcpSerializer();
	}

}
